<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>新增设备信息</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019072018:09" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190723" type="text/javascript" charset="utf-8"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .layui-card-header{
            border-bottom: 1px solid #eee;
        }
        .newTable{
            width: 80%;
            margin: 0 auto;
        }
        .layui-form .one{
            width: 100%;
            display: flex;
            flex-flow: row wrap;
            justify-content: space-around;
        }
        .layui-form-item{
            width: 33%;
        }
        .layui-inline{
            width: 40%;
            height: 38px;
        }
        .layui-form-label{
            width:64px;
        }
        .layui-input-block{
            margin-left: 94px;
        }
        select{
            width: 100%;
            height: 38px;
        }
        input::-webkit-input-placeholder {
            color: #aab2bd;
        }
        .buttonbottom{
            text-align: center;
        }
        .buttonbottom button{
            background-color: #009284;
            width: 90px;
            margin-top: 30px;
        }
        .layui-treeSelect .ztree li span.button.root_open:before, .layui-treeSelect .ztree li span.button.root_close:before{
            content: "\e623";
        }
    </style>
</head>
<body>
<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="formTest" action=""style="width: 100%;
            margin: 0 auto;">
                <input type="text" name="equipId" style="display: none" id="layui-form">
                <div class="one" style="padding-top: 20px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style=""><span style="color: red;">*</span>资产编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="equipNo" name="equipNo" lay-verify="required" placeholder="请输入设备编码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" style="float: right">
                        <label class="layui-form-label"><span style="color: red;">*</span>设备名称</label>
                        <div class="layui-input-block">
                            <input type="text"id="equipName" name="equipName"lay-verify="required" placeholder="请输入设备名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>型号</label>
                        <div class="layui-input-block">
                            <input type="text" name="modelNo" id="modelNo"lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>规格</label>
                        <div class="layui-input-block">
                            <input type="text" name="spec" id="spec" placeholder="请输入" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>生产厂家</label>
                        <div class="layui-input-block">
                            <input type="text" name="manufacturer" id="manufacturer" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>出厂编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="factoryNo" id="factoryNo" lay-verify="required"  placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>设备类型</label>
                        <div class="layui-input-block" id="equipmentType">
                            <input type="text" id="tree" lay-filter="tree" class="layui-input">
                            <input name="equipTypeId" type="hidden">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>所属部门</label>
                        <div class="layui-input-block">
                            <select name="deptId" style="" id="deptId" lay-filter="selectdept" >
                                <option></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">保管人</label>
                        <div class="layui-input-block">
                            <input type="text" name="custodian" id="custodian" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                </div>
                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>产权归属</label>
                        <div class="layui-input-block">
                            <select name="propertyId" lay-verify="required" style="" id="propertyId">
                                <option></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">设备功率</label>
                        <div class="layui-input-block">
                            <input type="text" name="accountFile" id="accountFile"   placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">设备序列号</label>
                        <div class="layui-input-block">
                            <input type="text" name="cloudSn" id="cloudSn" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">设备状况</label>
                        <div class="layui-input-block">
                            <select name="equipStatuasId" id="equipStatuasId" style="">
                                <option></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">供应商</label>
                        <div class="layui-input-block">
                            <input type="text" name="supplier"  id="supplier"  placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">资产来源</label>
                        <div class="layui-input-block">
                            <select name="sourceAssets" style="" id="sourceAssets">
                                <option></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item">
                        <label class="layui-form-label">资产原值</label>
                        <div class="layui-input-block">
                            <input type="text" name="assetsCost" id="assetsCost" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>出厂日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dateProduc" id="dateProduc" lay-verify="required" autocomplete="off" class="layui-input"  placeholder="yyyy-MM-dd" >
                        </div>
                    </div>
                    <div class="layui-form-item">

                    </div>
                </div>
                <div class="one hide choose" >
                    <div class="layui-form-item showF">
                        <label class="layui-form-label">方向</label>
                        <div class="layui-input-block">
                            <select name="directionId" id="directionId" lay-filter="aihao" style="" >
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text showF">
                        <label class="layui-form-label">灵敏度_X</label>
                        <div class="layui-input-block">
                            <input type="text" name="sensitivityX"  id="sensitivityX"  placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text hideF">
                        <label class="layui-form-label">灵敏度_Y</label>
                        <div class="layui-input-block">
                            <input type="text" name="sensitivityY" id="sensitivityY"   placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one hide choose2" >
                    <div class="layui-form-item hideF">
                        <label class="layui-form-label">灵敏度_Z</label>
                        <div class="layui-input-block">
                            <input type="text" name="sensitivityZ"  id="sensitivityZ"  placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">传感器类型/物理量</label>
                        <div class="layui-input-block">
                            <select name="phyQuantiId" id="phyQuantiId" style="">
                                <option placeholder="请选择"></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">输入模式/耦合方式</label>
                        <div class="layui-input-block">
                            <select name="couplingId" id="couplingId" style="">
                                <option></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="one">
                    <div class="layui-form-item" style="width:48%">
                        <label class="layui-form-label" >技术参数</label>
                        <div class="layui-input-block" >
                            <textarea name="technicalParm"  id="technicalParm" placeholder="请输入内容" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item" style="float: right;width:52%">
                        <label class="layui-form-label" >备注</label>
                        <div class="layui-input-block" >
                            <textarea name="memo"  id="memo" placeholder="请输入内容" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="buttonbottom">
                    <button id="submit" class="layui-btn layui-btn-sm"lay-submit lay-filter="formDemo" style="display: none"></button>
                    <button id="contiadd" data-type='1' class="layui-btn layui-btn-sm" style="background-color: white;border: 1px solid #009284;color: #009284">继续添加</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    var datas="";
    (function($){
        $.getUrlParam = function(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
        }
    })(jQuery);
    var idkey = $.getUrlParam("id");
    var type = $.getUrlParam("type");
    var name = $.getUrlParam("name");
    var pid=$.getUrlParam("pid")
    console.log(pid)
    var typeCode;
    $.ajax({
        type: 'get',
        url: '/equipTransfer/selectBypid',
        data:{pid:pid}
        ,dataType: 'json',
        success:function(res){
            var data=res.object;
            typeCode=data.equipTypeCode;
            console.log(typeCode)
            if(typeCode=="SENSOR"){
                 $(".hide").show();
            }else{
                $(".hide").hide();
            }
        }
    })
    //填充所属组织下拉框
    //lr 改动。
        $.ajax({
            type: 'get',
            url: '/equipmentScrapping/showUserAndDept',
            dataType: 'json',
            success: function (data) {
                var render = "<option class=''></option>";
                var t = data.data[1];
                for (var i = 0; i < t.length; i++) {
                    render+="<option class='' value=\"" + t[i].deptId + "\">" + t[i].deptName+ "</option>";
                }
                $("#deptId").html(render);
                layui.form.render('select');
            }
        })

    layui.use(['form', 'layer','layedit', 'laydate','element','treeSelect'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            , treeSelect = layui.treeSelect;
//下拉树加载
        function treeSelects(id,type){
            treeSelect.render({
                // 选择器
                elem: '#tree',
                // 数据
                data: '/equipmentType/selectEquipTypeTree',
                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '请选择',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function(d){
                    // console.log($('#'+d.current.tId).parent('ul').prev().attr('title'))
                    $('input[name="equipTypeId"]').val(d.current.id);

                    if($('#'+d.current.tId).parent('ul').prev().attr('title')=='传感器'){
                        $('#directionId option[value="SENSOR_DIRECTION3"]').prop('selected','selected');
                        shouHide('SENSOR_DIRECTION3')
                    }else{
                        $('#directionId option[value=""]').prop('selected','selected');
                        $(".hide").hide();
                    }
                    form.render()
                },
                // 加载完成后的回调函数
                success: function (d) {
                    console.log(d)
                    var treeId = $('#equipmentType .layui-treeSelect-body').attr('id')
                    var treeObj = $.fn.zTree.getZTreeObj(treeId)
                    var nodes = treeObj.transformToArray(treeObj.getNodes());
                    for (var i=0, l=nodes.length; i < l; i++) {
                        if (nodes[i].isParent){
                            treeObj.setChkDisabled(nodes[i], true);
                        }
                    }
                    if(id){
                        treeSelect.checkNode('tree',treeId,id);
                        shouHide(type)
                        for (var i=0, l=nodes.length; i < l; i++) {
                            if (nodes[i].id == id){
                                if($('#'+nodes[i].tId).parent('ul').prev().attr('title')=='传感器'){
                                    $('#directionId option[value="SENSOR_DIRECTION3"]').prop('selected','selected');
                                    // shouHide('SENSOR_DIRECTION3')
                                }
                            }
                        }
                    }
                    var dd = $('#equipmentType').find('input')[2];
                    $(dd).val(name);
                }
            });
        }
        form.on('select(aihao)', function(data){
            shouHide(data.value)
        });
        //结算组织监听事件
        form.on('select(selectdept)', function(data){
            var indiv=$("#ctree");
            $("#ctreediv").find("input[type='text']").remove();
            $("#ctreediv").find("div").remove();
            $("#ctreediv").append(indiv);
            ctree(null,data.value);
            form.render();
        });
        function ctree(id,deptId){
            var ctreeurldata=''; //场地位置
          /*  if (deptId!=undefined){
                ctreeurldata= '/limsMaterTool/LocationTree?deptId='+deptId
            }else {
                ctreeurldata='/limsMaterTool/LocationTree'
            }*/
            treeSelect.render({
                // 选择器
                elem: '#ctree',
                // 数据
                data:ctreeurldata ,
                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '请选择',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调3
                click: function(d){
                    // console.log($('#'+d.current.tId).parent('ul').prev().attr('title'))
                    $('input[name="positionId"]').val(d.current.id);
                    form.render()
                },
                // 加载完成后的回调函数
                success: function (d) {
                    var treeId = $('#ctreediv .layui-treeSelect-body').attr('id')
                    var treeObj = $.fn.zTree.getZTreeObj(treeId)
                    var nodes = treeObj.transformToArray(treeObj.getNodes());
                    for (var i=0, l=nodes.length; i < l; i++) {
                        if (nodes[i].isParent){
                            treeObj.setChkDisabled(nodes[i], true);
                        }
                    }
                    if(id){
                        treeSelect.checkNode('tree',treeId,id);
                        //console.log(type)
                        for (var i=0, l=nodes.length; i < l; i++) {
                            if (nodes[i].id == id){
                                if($('#'+nodes[i].tId).parent('ul').prev().attr('title')=='传感器'){
                                    $('#directionId option[value="SENSOR_DIRECTION3"]').prop('selected','selected');
                                    shouHide('SENSOR_DIRECTION3')
                                }
                            }
                        }
                    }
                }
            });
        }
        laydate.render({
            elem:'#recordDate'
            ,trigger: 'click'//呼出事件改成click
            ,format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem:'#dateProduc'
            ,trigger: 'click'//呼出事件改成click
            ,format: 'yyyy-MM-dd'
        });
        form.on('submit(formDemo)', function(object){
            console.log(object)
            var equipname = $('input[name="equipTypeId"]').val()
            console.log(equipname)
            datas = object.field;
            console.log(datas)
            var url=""
            if(type=="1"){
                url='/equipment/editEquipment';
            }else{
                url="/equipment/addEquipment";
            }
            if(equipname == ""){
                datas.equipTypeId = idkey;
            }
            $.ajax({
                type:'post',
                url:url,
                dataType:'json',
                data:datas,
                async:false,
                success:function(res){
                    layer.msg(res.msg, {
                        icon: 1,//提示的样式
                        time: 1200, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
                    });
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    // //子调父方法
                    window.parent.close();
                }
            })
            return false;
        })
        if(type=="1"){
            $(".buttonbottom").hide()
            $.ajax({
                type:'get',
                url:'/equipment/selectEquipmentByEquipId',
                dataType:'json',
                data:{equipId:idkey},
                success:function(res){
                    //如果 新增时未添加出厂日期和入账日期  点击编辑时默认给的日期是当前的日期
                    if(res.object.dateProduc == undefined){
                        res.object.dateProduc = nowformat();
                    } else{
                        res.object.dateProduc = format(res.object.dateProduc);
                    };
                    if(res.object.recordDate == undefined){
                        res.object.recordDate = nowformat();
                    } else{
                        res.object.recordDate = format(res.object.recordDate);
                    };
                    var data = res.object;
                    var treeId = $('.layui-treeSelect-body').attr('id')
                    treeSelects(res.object.equipTypeId,res.object.directionId);
                    ctree(res.object.positionId,res.object.deptId);
                    //回显编辑页面的值
                    setTimeout(function () {
                        form.val("formTest",data);
                    },1000)

                    //走下拉选择框后台接口
                    $.ajax({
                        url: '/equipCapy/selectCommonCode',
                        type: 'get',
                        dataType: 'json',
                        data:{
                            parentTypeNo:"PROPERTY_OWNER,EQUIP_STATUAS,SENSOR_DIRECTION,SENSOR_PHY_QUANTI,SENSOR_COUPLING,EQUIP_SOURCE_ASSETS"
                        },
                        success: function (ress) {
                            if(ress!=undefined&&ress.length>0){
                                var selectArray1=ress[0]; //分别定义六个选择
                                var selectArray2=ress[1];
                                var selectArray3=ress[2];
                                var selectArray4=ress[3];
                                var selectArray5=ress[4];
                                var selectArray6=ress[5];
                                if(selectArray1.length>0){
                                    var $select1=$("select[name='propertyId']");
                                    var optionStr='';
                                    for(var i=0;i<selectArray1.length;i++){
                                        var select1option=selectArray1[i];
                                        optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                                    }
                                    $select1.append(optionStr);
                                    //回显数据下拉框
                                    $('#propertyId').find('option[value="'+data.propertyId+'"]').prop('selected','selected');
                                    form.render();
                                }
                                if(selectArray2.length>0){
                                    var $select1=$("select[name='equipStatuasId']");
                                    var optionStr='';
                                    for(var i=0;i<selectArray2.length;i++){
                                        var select1option=selectArray2[i];
                                        optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                                    }
                                    $select1.append(optionStr);
                                    //回显数据下拉框
                                    $('#equipStatuasId').find('option[value="'+data.equipStatuasId+'"]').prop('selected','selected');
                                    form.render();
                                }
                                if(selectArray3.length>0){
                                    var $select1=$("select[name='directionId']");
                                    var optionStr='<option value="">请选择</option>';
                                    for(var i=0;i<selectArray3.length;i++){
                                        var select1option=selectArray3[i];
                                        optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                                    }
                                    $select1.html(optionStr);
                                    //回显数据下拉框
                                    $('#directionId').find('option[value="'+data.directionId+'"]').prop('selected','selected');
                                    form.render();
                                }
                                if(selectArray4.length>0){
                                    var $select1=$("select[name='phyQuantiId']");
                                    var optionStr='';
                                    for(var i=0;i<selectArray4.length;i++){
                                        var select1option=selectArray4[i];
                                        optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                                    }
                                    $select1.append(optionStr);
                                    //回显数据下拉框
                                    $('#phyQuantiId').find('option[value="'+data.phyQuantiId+'"]').prop('selected','selected');
                                    form.render();
                                }
                                if(selectArray5.length>0){
                                    var $select1=$("select[name='couplingId']");
                                    var optionStr='';
                                    for(var i=0;i<selectArray5.length;i++){
                                        var select1option=selectArray5[i];
                                        optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                                    }
                                    $select1.append(optionStr);
                                    //回显数据下拉框
                                    $('#couplingId').find('option[value="'+data.couplingId+'"]').prop('selected','selected');
                                    form.render();
                                }
                                if(selectArray6.length>0){
                                    var $select1=$("select[name='sourceAssets']");
                                    var optionStr='';
                                    for(var i=0;i<selectArray6.length;i++){
                                        var select1option=selectArray6[i];
                                        optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                                    }
                                    $select1.append(optionStr);
                                    //回显数据下拉框
                                    $('#sourceAssets').find('option[value="'+data.sourceAssets+'"]').prop('selected','selected');
                                    form.render();
                                }
                            }
                            form.render();
                            form.val("formTest",data);
                        }
                    })
                }
            })
        }else if(type=="0"){
            treeSelects();
            ctree();
            $.ajax({
                url: '/equipCapy/selectCommonCode',
                type: 'get',
                dataType: 'json',
                data:{
                    parentTypeNo:"PROPERTY_OWNER,EQUIP_STATUAS,SENSOR_DIRECTION,SENSOR_PHY_QUANTI,SENSOR_COUPLING,EQUIP_SOURCE_ASSETS"
                },
                success: function (ress) {
                    if(ress!=undefined&&ress.length>0){
                        var selectArray1=ress[0]; //分别定义六个选择
                        var selectArray2=ress[1];
                        var selectArray3=ress[2];
                        var selectArray4=ress[3];
                        var selectArray5=ress[4];
                        var selectArray6=ress[5];
                        if(selectArray1.length>0){
                            var $select1=$("select[name='propertyId']");
                            var optionStr=[];
                            for(var i=0;i<selectArray1.length;i++){
                                var select1option=selectArray1[i];
                                optionStr.push('<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>')
                            }
                            $("#propertyId").append(optionStr);
                        }
                        if(selectArray2.length>0){
                            var $select1=$("select[name='equipStatuasId']");
                            var optionStr=[];
                            for(var i=0;i<selectArray2.length;i++){
                                var select1option=selectArray2[i];
                                optionStr.push('<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>')
                            }
                            // $("#equipStatuasId").html(optionStr.join(""));
                            $("#equipStatuasId").append(optionStr);
                            //默认显示第一项
                            $('#equipStatuasId').find('option[value="'+selectArray2[0].codeTypeNo+'"]').prop('selected', 'ture');
                            form.render();
                        }
                        if(selectArray3.length>0){
                            var $select1=$("select[name='directionId']");
                            var optionStr='<option value="">请选择</option>';
                            for(var i=0;i<selectArray3.length;i++){
                                var select1option=selectArray3[i];
                                optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                            }
                            $select1.html(optionStr);
                        }
                        if(selectArray4.length>0){
                            var $select1=$("select[name='phyQuantiId']");
                            var optionStr='';
                            for(var i=0;i<selectArray4.length;i++){
                                var select1option=selectArray4[i];
                                optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                            }
                            $select1.html(optionStr);
                        }
                        if(selectArray5.length>0){
                            var $select1=$("select[name='couplingId']");
                            var optionStr='';
                            for(var i=0;i<selectArray5.length;i++){
                                var select1option=selectArray5[i];
                                optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                            }
                            $select1.append(optionStr);
                        }
                        if(selectArray6.length>0){
                            var $select1=$("select[name='sourceAssets']");
                            var optionStr='';
                            for(var i=0;i<selectArray6.length;i++){
                                var select1option=selectArray6[i];
                                optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                            }
                            $select1.append(optionStr);
                        }
                    }
                    form.render();
                }
            })
        }
    });
     shouHide("")
    //解决下拉框内有数据undefined问题
    function a(value) {
        if(value==undefined){
            return ""
        }
        return value
    }
    function shouHide(val) {
        if(val=="SENSOR_DIRECTION3"){
            $(".hide").show();
            $(".hideF").show();
            $(".showF").show();
            if($('#directionId').attr('dataType')=='1'){
                $('.choose2').find('.layui-form-item').eq(0).after($('.choose').find('.layui-form-item').eq(3))
                $('.choose2').find('.layui-form-item').eq(1).after($('.choose3').find('.layui-form-item').eq(2))
                $('.choose3').find('.layui-form-item').eq(1).after('<div class="layui-form-item"></div>')
            }

        }else if (val=="SENSOR_DIRECTION1") {
            $(".hide").show();
            $(".hideF").hide();
            $(".showF").show();
            $('.choose').find('.layui-form-item').eq(2).after($('.choose2').find('.layui-form-item').eq(1))
            $('.choose3').find('.layui-form-item').eq(2).remove();
            $('.choose3').find('.layui-form-item').eq(1).after($('.choose2').find('.layui-form-item').eq(1));
            $('#directionId').attr('dataType','1')
        }else{
            $(".hide").hide();
        }
    }
    //父级页面调用子级页面
    // function getnaStr(){
    //     $("#submit").click();
    // }
    //继续添加按钮事件
    $("#contiadd").click(function(){
        if($("#equipNo").val() == ""){
            layer.msg('设备编码不能为空！')
            return false;
        }else if($("#equipName").val() =='') {
            layer.msg('设备名称不能为空！')
            return false;
        }else if($("#modelNo").val() =='') {
            layer.msg('型号不能为空！')
            return false;
        }
        else if($("#spec").val() =='') {
            layer.msg('规格不能为空！')
            return false;
        }
        else if($("#factoryNo").val() =='') {
            layer.msg('出厂编号不能为空！')
            return false;
        }
        else if($("#manufacturer").val() =='') {
            layer.msg('生产厂家不能为空！')
            return false;
        }
        else if($("#dateProduc").val() =='') {
            layer.msg('出厂日期不能为空！')
            return false;
        }
        else if($("#propertyId").val() =='') {
            layer.msg('产权归属不能为空！')
            return false;
        }
        else if($("#deptId").val() =='') {
            layer.msg('所属组织不能为空！')
            return false;
        }
        // else if($('input[name="positionId"]').val() =='') {
        //     layer.msg('存放位置不能为空！')
        //     return false;
        // }
        else {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            // //子调父方法
            window.parent.close();
            //调用提交数据事件
            $("#submit").click();
            // 调用父页面新增事件
            window.parent.$("#addEq").click();
        }
    })
    //将毫秒数转为yyyy-MM-dd格式时间
    function format(t) {
        var  str = "";
        var nnow = new Date(t);
        var year = nnow.getFullYear();
        var month = nnow.getMonth()+1;
        var day = nnow.getDate();
        str = year+"-"+month+"-"+day;
        return str;
    }
    //获取当前时间  年月日
    function nowformat() {
        var  nstr = "";
        var now = new Date();
        var nyear = now.getFullYear();
        var nmonth = now.getMonth()+1;
        var nday = now.getDate();
        if(nmonth<10){
            nmonth = "0"+nmonth;
        }
        if(nday<10){
            nday = "0"+nday;
        }
        nstr = nyear+"-"+nmonth+"-"+nday;
        return nstr;
    }
    //监听设备类型下拉框
    $(function(){
        $("#equipmentType").click(function() {
            $(document).scrollTop(100)
            // $('.mbox').css('margin-bottom','40px')
        });
    })
</script>
</body>
</html>